<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/jsone/bootstrap.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/layer/layer.js"></script>
</head>

<body>
<div class="panel panel-info panel-content">
	<div class="panel-heading">
		<button  type="button" onclick="addvisit()" class="btn btn-info">
			<span class="glyphicon glyphicon-plus"></span>
			&nbsp;新增回访
		</button>
	</div>
	
	<table class="table table-hover table-bordered table-striped table-condensed" style="table-layout: fixed;">
		<thead>
			<tr>
				<th width="10%">#</th>
				<th width="25%">回访人</th>
				<th width="35%">回访内容</th>
				<th width="15%">回访时间</th>
				<th width="15%">操作</th>
			</tr>
		</thead>
		[#list pagination2.list as visit]
		<tr>
			<td align="center">${visit_index + 1 + pagination2.pageSize*(pagination2.pageNo-1)}</td>
			<td align="center">${visit.adminName!}</td>
			<td align="center" title="${visit.content!}"><p style="width:80%;white-space:nowrap;overflow:hidden;text-overflow: ellipsis;">${visit.content!}</p></td>
			<td align="center">${visit.createtime?string("yyyy-MM-dd HH:mm")!}</td>
			<td align="center">
				<button type="button" class="btn btn-danger btn-xs delbtn" onclick="edit('${visit.id}','${visit.companyId!}','${visit.userId!}','${visit.type!}','${visit.content!}')">编辑</button>
				<button type="button" class="btn btn-danger btn-xs delbtn" onclick="del('${visit.id}')">删除</button>
			</td>
		</tr>
		[/#list]
	</table>

	<div class="panel-footer">[@fenye p = pagination2 form = 'infoForm2' /]</div>
</div>


<!-- 新增的弹出页 -->
<div id="addvisit" style="width: 500px; height: 250px; display: none;">
	<form id="addform" method="post" class="form-horizontal" role="form">
		<input type="hidden" name="companyId" id="addcompanyid" value="${companyid!}">
		<input type="hidden" name="userId" id="adduserid" value="${userid!}">
		<!--  
		<input type="hidden" name="type" id="addtype" value="${type!}">
		-->
		<div class="form-group">
			<select class="form-control" name="type" id="addtype">
			    <option value="1">注册回访</option>
				<option value="2">采购询价回访</option>
				<option value="3">报价回访</option>
			</select>
		</div>

		<div class="form-group">
			<label class="col-sm-2 control-label" id="clickforpro">回访内容</label>
			<div class="col-sm-9">
				<textarea class="form-control" placeholder="" min="1" required="required" name="content" id="addcontent" style="height:150px"></textarea>
			</div>
		</div>
		<div class="form-group" style="margin-top: 15px;">
			<div class="col-sm-offset-3 col-sm-10">
				<input id="addsubmit" onclick="subadd()" type="button" class="btn btn-success" value="提交" />
			</div>
		</div>
	</form>
</div>

<!-- 编辑的弹出页 -->
<div id="editvisit" style="width: 500px; height: 250px; display: none;">
	<form id="editform" method="post" class="form-horizontal" role="form">
		<input type="hidden" name="id" id="editid">
		<input type="hidden" name="userId" id="edituserid">
		<input type="hidden" name="companyId" id="editcompanyid">
		<input type="hidden" name="type" id="edittype">

		<div class="form-group">
			<label class="col-sm-2 control-label" id="clickforpro">回访内容</label>
			<div class="col-sm-9">
				<textarea class="form-control" placeholder="" min="1" required="required" name="content" id="editcontent" style="height:150px"></textarea>
			</div>
		</div>
		<div class="form-group" style="margin-top: 15px;">
			<div class="col-sm-offset-3 col-sm-10">
				<input id="addsubmit" onclick="subedit()" type="button" class="btn btn-success" value="提交" />
			</div>
		</div>
	</form>
</div>

<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		$("#soform").attr("action", lpath + "?pageNo=" + 1);
	
		$("#soform").submit();
	}

	//展示新增窗口
	function addvisit() {
		dialog = art.dialog({
			title : "新增回访",
			lock : true,
			content : document.getElementById('addvisit')
		});
	}
	//删除
	function del(id) {//弹出警告框判断是否删除
		if (confirm('是否确认删除')) {
			$.ajax({
				url : '/returnvisit/ajax_del.do',
				type : 'get',
				dataType : 'json',
				data : {
					id : id
				},
				beforeSend : function() {
					art.dialog.tips("删除中...");
				},
				success : function(data) {
					if (data.success) {
						location.reload();
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		}
	}

	//打开编辑窗口
	function edit(id, companyid, userid, type, content) {
		$("#editid").val(id);
		$("#editcompanyid").val(companyid);
		$("#edituserid").val(userid);
		$("#edittype").val(type);
		$("#editcontent").val(content);
		dialog = art.dialog({
			title : "修改链接",
			lock : true,
			content : document.getElementById('editvisit')
		});
	}
	//新增提交
	function subadd(){
	[#--提交之前 form 要手动进行验证--]
	
	var content = $("#addcontent").val();
	if (!content) {
		alert('回访内容必须填写!');
		return;
	}
	var type = $("select[id='addtype']").val();
	if (!type) {
		alert('请选择回访类型!');
		return;
	}
	
	
	art.dialog.post({
		url: "/returnvisit/ajax_save.do",
        data:$("#addform").serialize(),
        success: function(data){
            if(data.success){
            	location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	
	}
	
	//编辑提交
	function subedit(){
	[#--提交之前 form 要手动进行验证--]
	
	var content = $("#editcontent").val();
	if (!content) {
		alert('回访内容必须填写!');
		return;
	}
	var type = $("select[id='edittype']").val();
	if (!type) {
		alert('请选择回访类型!');
		return;
	}
	art.dialog.post({
		url: "/returnvisit/ajax_edit.do",
        data:$("#editform").serialize(),
        success: function(data){
            if(data.success){
            	location.reload();
            }else{
            	alert(data.msg)
            }
        }
	},"加载中...");
	}
	

</script>
</body>